
package com.compuvest.web;

import java.io.Serializable;

public class Tracking implements Serializable {

    public final static int NONE =	0;
    public final static int BO =	1;
    public final static int SH =	2;
    public final static int SB =	3;
    public final static int SP =	4;
    public final static int NA =	5;
    public final static int DHL =	6;
    public final static int FDX =	7;
    public final static int UPS =	8;
    public final static int USPS =	9;

    private final static String[] messageLong = {
/*NONE*/ "",
/*BO  */ "<b>Your product is on backorder. Please contact customer service to check the current status at</b> <a href='mailto:info@compuvest.com'>info@compuvest.com</a>",
/*SH  */ "<font color=red>Your order has been shipped</font> as scheduled, however; due to the system updates we do not yet have the tracking number for this shipment. Please contact customer service at <a href='mailto:info@compuvest.com'>info@compuvest.com</a> to obtain additional information.",
/*SB  */ "<font color=red>Your order has been shipped</font>, however; one or more items were backordered. Due to the system updates we do not yet have the tracking number for this shipment. Please contact customer service at <a href='mailto:info@compuvest.com'>info@compuvest.com</a> for more details.",
/*SP  */ "<font color=red>Your order has been shipped</font> from more than one warehouse locations. Due to the system updates we do not yet have the tracking numbers for this shipment. Please contact customer service at <a href='mailto:info@compuvest.com'>info@compuvest.com</a> for more details.",
/*NA  */ "One or more items on your order is out of stock. You have been contacted by our sales representative (by email and/or phone) for possible replacements or cancellation. Please reply promptly with your decision or contact us at <a href='mailto:info@compuvest.com'>info@compuvest.com</a>",
/*DHL */ "<a href='http://track.dhl-usa.com/TrackByNbr.asp?ShipmentNumber=%s' target=_blank>%s</a>",
/*FDX */ "<a href='http://www.fedex.com/Tracking?action=track&language=english&cntry_code=us&mps=y&ascend_header=1&tracknumbers=%s' target=_blank>%s</a>",
/*UPS */ "<a href='http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=%s' target=_blank>%s</a>",
/*USPS*/ "<a href='http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=%s' target=_blank>%s</a>"
    };

    private final static String[] messageShort = {
/*NONE*/ "Processing...",
/*BO  */ "Processing...",
/*SH  */ "Processing...",
/*SB  */ "Processing...",
/*SP  */ "Processing...",
/*NA  */ "Processing...",
/*DHL */ messageLong[DHL],
/*FDX */ messageLong[FDX],
/*UPS */ messageLong[UPS],
/*USPS*/ messageLong[USPS]
    };

    private String trackingNo = "";
    private String shippDate = "";

    public Tracking() {
	this("", "");
    }

    public Tracking(String trackingNo, String shippDate) {
	this.trackingNo = trackingNo;
	this.shippDate = shippDate;
    }

    public String getTrackingNo()	{ return trackingNo; }
    public String getShippDate()	{ return shippDate; }

//
    public String getStatusShort() {

	switch(trackingNo.length()) {
	    case 2 :
		if     ("BO".equals(trackingNo)) return messageShort[BO];
		else if("SH".equals(trackingNo)) return messageShort[SH];
		else if("SB".equals(trackingNo)) return messageShort[SB];
		else if("SP".equals(trackingNo)) return messageShort[SP];
		else if("NA".equals(trackingNo)) return messageShort[NA];
		else return messageShort[NONE];

	    case 10 : return String.format(messageShort[DHL], trackingNo, trackingNo);
	    case 12 :
	    case 15 : return String.format(messageShort[FDX], trackingNo, trackingNo);
	    case 11 :
	    case 18 : return String.format(messageShort[UPS], trackingNo, trackingNo);
	    case 13 :
	    case 22 : return String.format(messageShort[USPS], trackingNo, trackingNo);
	    default : return  messageShort[NONE];
	}
    }

    public String getStatusLong() {

	switch(trackingNo.length()) {
	    case 2 :
		if     ("BO".equals(trackingNo)) return messageLong[BO];
		else if("SH".equals(trackingNo)) return messageLong[SH];
		else if("SB".equals(trackingNo)) return messageLong[SB];
		else if("SP".equals(trackingNo)) return messageLong[SP];
		else if("NA".equals(trackingNo)) return messageLong[NA];
		else return messageLong[NONE];

	    default : return  messageLong[NONE];
	}
    }

    public String getShippingCompany() {

	switch(trackingNo.length()) {
	    case 10 : return "DHL";
	    case 12 :
	    case 15 : return "Fedex";
	    case 11 :
	    case 18 : return "UPS";
	    case 13 :
	    case 22 : return "USPS";
	    default : return "";
	}
    }
}
